<template>
  <div class="flow-box">
    <!-- 流转记录 -->
    <EmptyBox
      v-if="results.length == 0"
      :title="t('当前无相关流转记录')"
      :desc="t('流程需发起后才会有流转记录产生')"
    />
    <div class="relative" v-else>
      <a-button type="primary" class="!absolute right-0 cursor-pointer z-99" @click="selfHandle">{{
        btnText ? '仅查看本人' : '查看所有'
      }}</a-button>
      <a-tabs v-model:activeKey="activeKey">
        <a-tab-pane v-for="(parent, idx) in results" :key="idx" :tab="t(parent.schemaName)">
          <div class="card-box" v-for="(item, index) in parent.records" :key="index">
            <div class="card-item" v-if="index % 2 == 0">
              <div class="card basic">
                <div class="node-box">
                  <span class="icon blue"></span>
                  <span class="title">{{ t('节点名称') }}</span>
                  <span class="sign">: </span>
                  <span class="text color2">{{ item.nodeName }}</span></div
                >
                <div class="node-box">
                  <span class="icon green"></span>
                  <span class="title">{{ t('审批信息') }}</span>
                  <span class="sign">: </span>
                  <span class="text">{{ item.comment }}</span>
                </div>
              </div>
              <div class="dot-box"
                ><div class="line"></div><div class="dot"></div><div class="line"></div
              ></div>
              <div class="date basic">{{ item.startTime }}</div>
            </div>
            <div class="card-item" v-else>
              <div class="date basic date-padding date-right">{{ item.startTime }}</div>
              <div class="dot-box"
                ><div class="line"></div><div class="dot"></div><div class="line"></div
              ></div>
              <div class="card basic">
                <div class="node-box">
                  <span class="icon blue"></span>
                  <span class="title">{{ t('节点名称') }}</span>
                  <span class="sign">: </span>
                  <span class="text color2">{{ item.nodeName }}</span></div
                >
                <div class="node-box">
                  <span class="icon green"></span>
                  <span class="title">{{ t('审批信息') }}</span>
                  <span class="sign">: </span>
                  <span class="text">{{ item.comment }}</span>
                </div>
              </div>
            </div>
          </div>
        </a-tab-pane>
      </a-tabs>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import EmptyBox from './EmptyBox.vue';
  import { getSelfRecords } from '/@/api/workflow/process';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { TaskRecordList } from '/@/model/workflow/bpmnConfig';
  const { t } = useI18n();

  const props = defineProps({
    list: { type: Array as PropType<TaskRecordList[]> },
    processId: String,
  });
  const results = ref<TaskRecordList[]>(props.list || []);
  const activeKey = ref(0);
  const btnText = ref(true);
  function selfHandle() {
    results.value = [];
    if (btnText.value) {
      getSelfRecords({ processId: props.processId }).then((res) => {
        if (res.taskRecords) {
          results.value.push({
            records: res.taskRecords,
            schemaName: '当前流程',
          });
        }

        if (res.otherProcessApproveRecord) {
          results.value = results.value.concat(res.otherProcessApproveRecord);
        }
      });
    } else {
      results.value = props.list || [];
    }

    btnText.value = !btnText.value;
  }
</script>

<style lang="less" scoped>
  .flow-box {
    height: 80vh;
    overflow: auto;
    padding: 0 20px;
  }

  .dot-box {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    .dot {
      width: 16px;
      height: 16px;
      border: 2px solid;
      border-color: @primary-color;
      border-radius: 50%;
    }

    .line {
      flex: 1;
      width: 2px;
      background-color: #f1f1f1;
    }
  }

  .date {
    align-self: center;
    padding: 10px;
    margin: 30px;
  }

  .date-right {
    text-align: right;
  }

  .date-padding {
    padding-left: 20%;
  }

  .card-item {
    display: flex;
  }

  .basic {
    flex-basis: 40%;
  }

  .card {
    height: 100%;
    background-color: #fafafa;
    border: 1px solid #ebeef5;
    box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
    border-radius: 10px;
    padding: 10px;
    margin: 30px;
  }

  .node-box {
    display: flex;
    align-items: flex-start;
    margin: 10px 0;

    .icon {
      width: 6px;
      height: 20px;
      margin-right: 10px;
    }

    .blue {
      background-color: #5e95ff;
    }

    .green {
      background-color: #95f204;
    }

    .title {
      font-size: 14px;
      font-weight: 700;
    }

    .sign {
      margin: 0 10px;
    }

    .text {
      line-height: 22px;
      color: #999;
      flex: 1;
    }

    .color2 {
      color: #666;
    }
  }
</style>
